var admims_base = {
	init:function()
	{
		admims_base.intLeftMenu();							
	},
	intLeftMenu:function()
	{
		//int left menu	
		var  $that = this;
		var $memu = $('#admins-left-box').find('.title');
		var $memuList = $memu.children('span');
	    if($memuList.length > 0){
			
		   $memuList.each(function(){
                 var $toggle = $(this);
				 if($toggle.length > 0){
					 
					 $toggle.parent().on('click',function(){
						$that.toggleLeftMenu($(this).children('span'),$that);
					 });
					 
					 $that.initCurrentMenu($(this));
					 
				 }
            });
			
			   
		}
	},
	toggleLeftMenu:function($self,$that){
		var $parent = $self.parent().parent();
		var $submenu = $parent.find('.nav-sidebar');
		if($submenu.length > 0){
			if($submenu.is(':hidden')){
				$that.hideCurrentMenu($that);
				$submenu.slideDown();
				$submenu.data('current',1);
				$self.removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
			}else{
				$submenu.data('current',0);
				$submenu.slideUp();
				$self.removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
			}
			
		}
	},
	initCurrentMenu:function($self){
		var $parent = $self.parent().parent();
		var $submenu = $parent.find('.nav-sidebar');
		if($submenu.length > 0){
			$submenu.each(function(){
				 var $submenuUl = $(this);
                 var $submenuLi = $submenuUl.find('li');
				 if($submenuLi.length > 0){
					 $submenuUl.data('current',0);
					 $submenuLi.each(function(){
						 var curr = $(this).data('current');
						 if(curr==1){
							$submenuUl.data('current',1);
							$submenuUl.slideDown();
				            $self.removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
						 }
					 });
				 }
            });
		}
	},
	hideCurrentMenu:function($that){
		var $submenu = $('#admins-left-box').find('.nav-sidebar');
		if($submenu.length > 0){
			$submenu.each(function(){
				var curr = $(this).data('current');
				if(curr==1){
					$(this).data('current',0);
				    $(this).slideUp();
			        $(this).parent().find('.title').children('span').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
				}
			});
		}
	}
	
	
}


$(function(){
    admims_base.init();
});